<?php

/**
 * O2O团购PC版本
 * ============================================================================
 * * 版权所有 2009-2016 郑州司科计算机科技有限公司，并保留所有权利。
 * 购买网址: http://www.jzphp.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
  * 咨询电话：400-823-0371 QQ：313999875
 * ============================================================================
 * $Author: zzsike $
 * $Time 2016-02-03 sammy $
*/


require_once(dirname(dirname(__FILE__)) . '/appwap.php');

$cid = $_GET['cid'];
$sort = $_GET['sort'];
$onclickcate = Table::Fetch('category', $cid, 'id');
$allcategories = DB::LimitQuery('category', array(
	'condition' => array(
		'zone' => 'credit',
		'display' => 'Y',
	),
	'order' => 'ORDER BY id ASC',
));


if($sort == 0){
	$order='ORDER BY id DESC, score DESC, time DESC';
}elseif($sort == 1){
	$order='ORDER BY time DESC, id DESC';
}elseif($sort == 2){
	$order='ORDER BY score ASC';
}else{
	$order='ORDER BY score DESC';
}

if($cid==0){
	$classify = Utility::GetColumn($allcategories,'id');
	$allclassify = implode(',',$classify);
	$condition = array(
		"classify in ($allclassify)",
		'display' => 'Y',
	);
	$count = Table::Count('goods', $condition);
	list($pagesize, $offset, $pagestring) = pagestring($count, 12);	
	$creditexchange = DB::LimitQuery('goods', array(
		'condition' => $condition,
		'order' => $order,
		'size' => $pagesize,
		'offset' => $offset,
	));
}else{
	$condition = array(
		'classify' => $cid,
		'display' => 'Y',
	);
	$count = Table::Count('goods', $condition);
	list($pagesize, $offset, $pagestring) = pagestring($count, 12);
	$creditexchange = DB::LimitQuery('goods', array(
		'condition' => $condition,
		'order' => $order,
		'size' => $pagesize,
		'offset' => $offset,
	));
}
$pagetitle = '积分兑换分类';
include template('m_creditclassify');
?>